/**
 * @extends noty
 * @description Extends the noty plugin
 */
$.noty.defaults = {
  layout: 'top',
  theme: 'defaultTheme',
  type: 'alert',
  text: '',
  dismissQueue: false,
  template: '<div class="noty_message"><span class="noty_text"></span><div class="noty_close"></div></div>',
  animation: {
    open: {
      height: 'toggle'
    },
    close: {
      height: 'toggle'
    },
    easing: 'swing',
    speed: 200
  },
  timeout: 3000,
  force: false,
  modal: false,
  closeWith: ['click'],
  callback: {
    onShow: function() {},
    afterShow: function() {},
    onClose: function() {},
    afterClose: function() {}
  },
  buttons: false
};


/**
 * @extends dataTables
 * @description Extends the dataTable plugin to use Bootstrap classes
 */

// Set the defaults for DataTables initialisation
$.extend(true, $.fn.dataTable.defaults, {
  sDom: "<'row-fluid'<'span12'f>r>t<'row-fluid'<'span4'l><'span4'i><'span4'p>>",
  sPaginationType: "bootstrap",
  oLanguage: {
    sLengthMenu: "_MENU_ registros por página",
    sZeroRecords: "Nenhum registro encontrado.",
    sInfo: "<i class='icon-search'></i> _START_ de _END_. Total: _TOTAL_ registros.",
    sInfoEmpty: "Exibindo 0 resultados.",
    sInfoFiltered: "(filtrados de um total de _MAX_ registros)",
    sSearch: "",
    oPaginate: {
      sPrevious: "Anterior",
      sNext: "Próximo"
    }
  }
});

// Default class modification
$.extend($.fn.dataTableExt.oStdClasses, {
  sWrapper: "dataTables_wrapper form-inline"
});

// API method to get paging information
$.fn.dataTableExt.oApi.fnPagingInfo = function(oSettings) {
  return {
    iStart: oSettings._iDisplayStart,
    iEnd: oSettings.fnDisplayEnd(),
    iLength: oSettings._iDisplayLength,
    iTotal: oSettings.fnRecordsTotal(),
    iFilteredTotal: oSettings.fnRecordsDisplay(),
    iPage: oSettings._iDisplayLength === -1 ? 0 : Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength),
    iTotalPages: oSettings._iDisplayLength === -1 ? 0 : Math.ceil(oSettings.fnRecordsDisplay() / oSettings._iDisplayLength)
  };
};

// Bootstrap style pagination control
$.extend($.fn.dataTableExt.oPagination, {
  "bootstrap": {
    "fnInit": function(oSettings, nPaging, fnDraw) {
      var oLang = oSettings.oLanguage.oPaginate;
      var fnClickHandler = function(e) {
        e.preventDefault();
        if (oSettings.oApi._fnPageChange(oSettings, e.data.action)) {
          fnDraw(oSettings);
        }
      };

      $(nPaging).addClass('pagination').append(
        '<ul>' +
        '<li class="prev disabled"><a href="#"><i class="icon-double-angle-left"></i></a></li>' +
        '<li class="next disabled"><a href="#"><i class="icon-double-angle-right"></i></a></li>' +
        '</ul>');
      var els = $('a', nPaging);
      $(els[0]).bind('click.DT', {
        action: "previous"
      }, fnClickHandler);
      $(els[1]).bind('click.DT', {
        action: "next"
      }, fnClickHandler);
    },
    "fnUpdate": function(oSettings, fnDraw) {
      var iListLength = 5;
      var oPaging = oSettings.oInstance.fnPagingInfo();
      var an = oSettings.aanFeatures.p;
      var i, ien, j, sClass, iStart, iEnd, iHalf = Math.floor(iListLength / 2);

      if (oPaging.iTotalPages < iListLength) {
        iStart = 1;
        iEnd = oPaging.iTotalPages;
      } else if (oPaging.iPage <= iHalf) {
        iStart = 1;
        iEnd = iListLength;
      } else if (oPaging.iPage >= (oPaging.iTotalPages - iHalf)) {
        iStart = oPaging.iTotalPages - iListLength + 1;
        iEnd = oPaging.iTotalPages;
      } else {
        iStart = oPaging.iPage - iHalf + 1;
        iEnd = iStart + iListLength - 1;
      }

      for (i = 0, ien = an.length; i < ien; i++) {
        // Remove the middle elements
        $('li:gt(0)', an[i]).filter(':not(:last)').remove();

        // Add the new list items and their event handlers
        for (j = iStart; j <= iEnd; j++) {
          sClass = (j == oPaging.iPage + 1) ? 'class="active"' : '';
          $('<li ' + sClass + '><a href="#">' + j + '</a></li>')
            .insertBefore($('li:last', an[i])[0])
            .bind('click', function(e) {
            e.preventDefault();
            oSettings._iDisplayStart = (parseInt($('a', this).text(), 10) - 1) * oPaging.iLength;
            fnDraw(oSettings);
          });
        }

        // Add / remove disabled classes from the static elements
        if (oPaging.iPage === 0) {
          $('li:first', an[i]).addClass('disabled');
        } else {
          $('li:first', an[i]).removeClass('disabled');
        }

        if (oPaging.iPage === oPaging.iTotalPages - 1 || oPaging.iTotalPages === 0) {
          $('li:last', an[i]).addClass('disabled');
        } else {
          $('li:last', an[i]).removeClass('disabled');
        }
      }
    }
  }
});


/**
 * Bootstrap-Password-Strength                                                                                                                                              [description]
 */
var getPasswordStrength;getPasswordStrength=function(e){var t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m;s=e.length;o=0;if(s>=8){o=3}if(s>=5&&s<8){o=2}if(s<6){o=0}c=e.split("");n=[];for(p=0,v=c.length;p<v;p++){t=c[p];if(t===t.toUpperCase()){n.push(t)}}h=0;if(n.length===0){h=0}if(n.length===1){h=2}if(n.length>1){h=3}a=new RegExp("^(a-z|A-Z|0-9)*[^#$%^&*()'*$!\"£]");i=e.split("");r=0;for(d=0,m=i.length;d<m;d++){t=i[d];if(t.match(a)){r++}}l=e.length-r;if(l>0){f=3}else{f=1}u=o+h+f;return u};$(document).ready(function(){$("#senha").keyup(function(){var e;e=getPasswordStrength($("#senha").val());$("#senha").removeClass("passwordWeak");$("#senha").removeClass("passwordMedium");$("#senha").removeClass("passwordStrong");$("#passwordStrengthLabel").removeClass("passwordWeakLabel");$("#passwordStrengthLabel").removeClass("passwordMediumLabel");$("#passwordStrengthLabel").removeClass("passwordStrongLabel");if(e<=3){$("#senha").addClass("passwordWeak");$("#passwordStrengthLabel").text("Weak");$("#passwordStrengthLabel").addClass("passwordWeakLabel")}if(e>3&&e<7){$("#senha").addClass("passwordMedium");$("#passwordStrengthLabel").text("Medium");$("#passwordStrengthLabel").addClass("passwordMediumLabel")}if(e>=7){$("#senha").addClass("passwordStrong");$("#passwordStrengthLabel").text("Strong");return $("#passwordStrengthLabel").addClass("passwordStrongLabel")}});return $("#senha").focusout(function(){return $("#passwordStrengthLabel").text("")})})